package cn.erperp;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;

/**
 * Hello world!
 */
public class SimpleApp {

    public static void main(String[] args) {
        String logFile = "README.md"; // Should be some file on your system
        SparkConf conf = new SparkConf().setMaster("local").setAppName("Simple Application");
        JavaSparkContext sc = new JavaSparkContext(conf);
        JavaRDD<String> logData = sc.textFile(logFile).cache();

        long numSpark = logData.filter(new Function<String, Boolean>() {
            public Boolean call(String s) {
                return s.contains("spark");
            }
        }).count();

        long numBs = logData.filter(new Function<String, Boolean>() {
            public Boolean call(String s) {
                return s.contains("m");
            }
        }).count();

        System.out.println("Lines with spark: " + numSpark + ", lines with m: " + numBs);
    }
}
